

// simple
UserDefaults.standard.set("String",forKey:"Key")
let string  = UserDefaults.standard.object(forKey:"Key")

// different types
let userDefaults = UserDefaults.standard

userDefaults.set(7,forKey:"number")
userDefaults.integer(forKey:"number")

userDefaults.set(true,forKey:"Bool")
userDefaults.bool(forKey:"Bool")

userDefaults.set("Batman",forKey:"String")
userDefaults.object(forKey:"String") as! String

userDefaults.set(NSDate(),forKey:"date")
userDefaults.object(forKey:"date") as! NSDate

userDefaults.set(["s1","s2","s3"],forKey:"array")
userDefaults.object(forKey:"array") as? [String]??[String]()

// verify value exits
if let name = userDefaults.object(forKey:"name") as? String {
    print(name)
}

